<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<jsp:include page="../common/common.jsp"></jsp:include>

</head>
<body>
	<script type="text/javascript"
		src="${pageContext.request.contextPath}/js/crud.js"></script>
   <script type="text/javascript">
   var tbId ='tt';
	var dialogId ='dd';
	var formId = 'ff';
	var baseUrl = '${pageContext.request.contextPath}/student/';
	$(function() {
		//alert("onload方法....");
		var url = baseUrl + 'findAll.do';
		//var tableId ='mainTableId';
		var title = '主表选项';
		var toolbarId = 'myTool';
		initpage(tbId, title, toolbarId, url)
	});
	function update() {
		var url = baseUrl + 'findById.do?id=';
		var title = '修改';
		edit(tbId, title, formId, url);
	}
	function addStudent() {

		var xxx = '${pageContext.request.contextPath}/class/findAllSelectionDTO.do';
		add('新增', 'detailDialogId', 'detailFormId', tbId);
		$.ajax({
			url : xxx,
			type : 'post',
			success : function(data) {
				var themecombo2 = [ {
					'text' : '请选择',
					'id' : ''
				} ];
				for (var i = 0; i < data.length; i++) {
					themecombo2.push({
						"text" : data[i].text,
						"id" : data[i].id
					});
				}
				$("#classId").combobox("loadData", themecombo2);
			}
		});
	}
	function dels() {
		var url = baseUrl + 'deleteByIds.do';
		del(tbId, url);
	}
	function certains() {
		var url = baseUrl;
		certain(str, formId, url, dialogId, tbId);
	}

	//查询
	function searchName() {
		var studentName = $("input[name=student]").val();
		//load作用：装载第一次进入页面的请求，并且可以传递参数，参数列表用对象包装
		$("#" + tbId).datagrid('load', {
			'studentName' : studentName,
		});
	}
	function save() {
		//	alert("------");
		var url = baseUrl;
		str = 'add.do';
		// certain(str,'detailDialogId',url,'detailFormId',tbId);
		$('#detailFormId').form('submit', {
			url : url + str,
			onSubmit : function() {
				var result = $(this).form('validate');
				return result;
			},
			success : function(jsonData) {
				$("#detailDialogId").dialog('close');
				var data = eval('(' + jsonData + ')');
				if (data.result == "success") {
					$.messager.show({
						title : '提示',
						msg : data.msg,
						timeout : 2000,
						showType : 'slide'
					});
					$("#" + tbId).datagrid('reload');
				}
			}
		});
	}

   </script>
		
	<table id="tt">
		<thead>
			<tr>
				<th data-options="field:'id',checkbox:true" width="80">ID</th>
				<th field="studentName" width="100">学生姓名</th>
				<th field="age" width="100">学生年龄</th>
				<th field="phone" width="100">手机号码</th>
				<th field="className" width="100">所在班级</th>
			</tr>
		</thead>
	</table>
	<div id="myTool">
		<form id="mySearch" action="">
			姓名:<input id="searchBox" tboxclass="easyui-text" name="student" /> <a
				href="#" class="easyui-linkbutton" iconCls="icon-search"
				plain="ture" onclick="searchName()">查询</a>
		</form>
		<a class="easyui-linkbutton" iconCls="icon-add"
			onclick="addStudent();">增加</a> <a class="easyui-linkbutton"
			iconCls="icon-remove" onclick="dels();">删除</a> <a
			class="easyui-linkbutton" iconCls="icon-edit" onclick="update();">修改</a>
	</div>
	<div id="dd" style="display: none;">
		<form method="post" id="ff">
			<table>
				<tr>
					<td>姓名:</td>
					<td><input type="text" class="easyui-validatebox"
						name="studentName" data-options="required:true"></td>
					<input type="hidden" name="id">
				</tr>
				<tr>
					<td>年龄:</td>
					<td><input type="text" class="easyui-validatebox" name="age"
						data-options="required:true"></td>
				</tr>
				<tr>
					<td>手机号码:</td>
					<td><input type="text" class="easyui-validatebox" name="phone"
						data-options="required:true"></td>
				</tr>
				<tr>
					<td>班级:</td>
					<td><input type="text" class="easyui-validatebox"
						name="classId" data-options="required:true"></td>
				</tr>
				<tr>
					<td><a class="easyui-linkbutton" iconCls="icon-ok"
						onclick="certains();">确定 </a></td>
					<td><a class="easyui-linkbutton" iconCls="icon-undo">取消</a></td>
				</tr>
			</table>
		</form>
	</div>

	<div id="detailDialogId" style="display: none">
		<form id="detailFormId" method="post">
			<table>
				<tr>
					<td>学生姓名：</td>
					<td><input class="easyui-validatebox"
						data-options="required:true" name="studentName" /></td>
				</tr>
				<tr>
					<td>年龄姓名：</td>
					<td><input class="easyui-validatebox"
						data-options="required:true" name="age" /></td>
				</tr>
				<tr>
					<td>电话号码：</td>
					<td><input class="easyui-validatebox"
						data-options="required:true" name="phone" /></td>
				</tr>
				<tr>
					<td>班级：</td>
					<td>
						<!-- valueField 往后台传的值  1 --> <!-- textField  前台显示的值   学历  --> <input
						id="classId" class="easyui-combobox" name="classId"
						style="width: 160px;"
						data-options="editable:false,valueField:'id', textField:'text'" />

					</td>
					<!-- 有些东西 我们后台需要 但是前台不显示的处理方法....  hidden -->
					<input type="hidden" name="id" />
					<!-- 有些东西 我们后台需要 但是前台不显示的处理方法....  hidden -->
				</tr>
				<tr>
					<td><a class="easyui-linkbutton" iconCls="icon-ok"
						onclick="save();">保存</a></td>
				</tr>
			</table>
		</form>
	</div>
</body>

</html>